/**
 * @author vivi
 * @description
 * @date 2024/4/25
 */
public class demo1 {
    //回文子串
    public int getLongestPalindrome (String s) {
        // write code here
        int lenS = s.length();
        //定义回文子串的长度
        int length = 0;

        for (int i = 0; i < lenS; i++) {
            // lenS是奇数
            int left = i - 1;
            int right = i + 1;
            while(left >= 0 && right < lenS && s.charAt(left) == s.charAt(right)){
                left--;
                right++;
            }
            length = Math.max(length,right - left - 1);

            // 当⻓度为偶数的时候
            left = i; right = i + 1;
            while(left >= 0 && right < lenS && s.charAt(left) == s.charAt(right))
            {
                left--;
                right++;
            }
            length = Math.max(length, right - left - 1);
        }

        return length;
    }
}
